<template>
  <div class="answers">
    <div class="header_zb_block">
      <div class="header_zb_list">
        <h4 class="header_zb_title">我的工作台</h4>
        <ul class="header_zb_list_ul">
          <li class="header_zb_list_items" @click="handleZbItemClick('ZB','待办工单','TODO_TASK')" >
            <span class="header_zb_list_bg">待办工单</span>
            <span class="header_zb_list_digital" v-show="toDoSize !== 0">{{ toDoSize }}</span>
          </li>
          <li class="header_zb_list_item" @click="handleZbItemClick('ZB','已办工单','DONE_TASK')" >已办工单</li>
          <li class="header_zb_list_item" @click="handleZbItemClick('ZB','我的工单','MY_APPLICANT')" >我的工单</li>
          <li class="header_zb_list_items" @click="handleZbItemClick('ZB','我的待阅','TO_READ')" >
            <span class="header_zb_list_bg">我的待阅</span>
            <span class="header_zb_list_digital" v-show="toReadSize !== 0">{{ toReadSize }}</span>
          </li>
          <li class="header_zb_list_item" @click="handleZbItemClick('ZB','我的已阅','TO_READ')" >我的已阅</li>
        </ul>
        <h4 class="header_zb_title">常用工具</h4>
        <ul class="header_zb_list_ul">
          <li class="header_zb_list_item" @click="inTellingPatrolInspect()">智能巡检</li>
          <li class="header_zb_list_item" @click="goToChapterApply()">用章申请</li>
          <li class="header_zb_list_item" @click="openWorkReminder()" v-if="$store.state.thePartyBranch321.hasWorkReminderRole && $store.state.thePartyBranch321.thePartyBranchRemind">321提醒</li>
          <li class="header_zb_list_item" @click="goToMeetingManagement">会议管理</li>
        </ul>
      </div>
    </div>

  </div>
</template>

<script>
import getTime from '@/utils/getTime.js'
import {setQueryInTellingPatrolInspect, setQueryTaskList, setRoleMsg} from '@/utils/setChatStoreData.js'
import {mapState} from "vuex";
import router from "@/router";
import API from '@/api/api-chat-list.js'
/* 可以发起印章申请的角色： 书记、党办主任(专业管理员)、公司党委委员 */
export const CHAPTER_ROLE_CONFIG  = ['GANSHI', 'PROVINCE_LEADER', 'PROVINCE_DW', 'BRANCH_LEADER', 'BRANCH_DW']
/* 用章申请权限验证 */
export const PROVINCE_DN = 'O=zmcc'
/* 智能巡检 */
export const INSPECTION = '智能巡检';
/* 智能巡检类型 */
export const INSPECTION_TYPE = 'inTellingPatrolInspect';
/* 用章申请页面路径 */
export const CHAPTER_APPLY_URL = '/chapterApplyIndex';
/* 用章申请 */
export const CHAPTER_APPLY = '用章申请';
export default {
  name: "HeaderZB",
  data(){
    return {
      toDoSize:0,//待办工单数量
      toReadSize:0,//待阅数量
      page:1,//默认页数
      pageSize:10,//默认数量
    }
  },
  methods: {
    // 快捷导航列表按钮事件
    handleZbItemClick(category, workOrderName, workOrderType) {
      setQueryTaskList(this, workOrderName, workOrderType);
    },
    inTellingPatrolInspect(){
      const flag = this.$store.state.userInfo.purviewEnums.find(role => {
        return CHAPTER_ROLE_CONFIG.includes(role);
      });
      flag ? setQueryInTellingPatrolInspect(this, INSPECTION, INSPECTION_TYPE) : setRoleMsg(this,INSPECTION);
    },
    async goToChapterApply() {
      const flag = this.$store.state.userInfo.companyDN === PROVINCE_DN && this.$store.state.userInfo.purviewEnums.find(role => {
        return CHAPTER_ROLE_CONFIG.includes(role);
      });
      if (flag) {
        await router.push(CHAPTER_APPLY_URL);
      }else {
        setRoleMsg(this, CHAPTER_APPLY);
      }
    },
    //321提醒按钮
    openWorkReminder(){
      this.$router.push('PartyBranchWork')
    },
    /**
     * 跳转会议管理页面
     */
    goToMeetingManagement() {
      this.$router.push('/meetingList');
    }
  },
  computed: {
    ...mapState(['robotInfo', 'rhPlate']),
    getTimes() {
      return getTime();
    }
  },
  async created(){
    //并发请求待办数量和待阅数量并赋值
    [{totalCount : this.toDoSize}, {total : this.toReadSize}] =
        (await Promise.all(['TODO_TASK', 'TO_READ'].map(type =>
            API.queryTaskList({type, "page" : this.page, "pageSize" : this.pageSize})
        ))).map(result => result?.data);
  }
}
</script>

<style scoped lang="less">
@import url("~@/assets/css/homeDJHeader/HeaderZB.css");
</style>
